﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace FlickrHarmony {
    public partial class AuthForm : Form {
        public string Frob { get; set; }

        public AuthForm() { InitializeComponent(); }

        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
            this.Frob = Plugin.Flickr.AuthGetFrob();
            string flickrUrl = Plugin.Flickr.AuthCalcUrl(this.Frob, FlickrNet.AuthLevel.Read);
            System.Diagnostics.Process.Start(flickrUrl);
            Thread.Sleep(2000);
        }

        private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
            if (!e.Cancelled) { base.DialogResult = DialogResult.OK; }
        }

        private void btnAuthorize_Click(object sender, EventArgs e) {
            btnAuthorize.Enabled = false;
            BackgroundWorker.RunWorkerAsync();
        }

		private void btnCancel_Click(object sender, EventArgs e) {
			if (BackgroundWorker.IsBusy) { BackgroundWorker.CancelAsync(); }
			base.DialogResult = DialogResult.Cancel;
		}
    }
}